﻿using MediatR;
using SystemLYH.API.Application.Command.QualityCommand;
using SystemLYH.Infrstructre.Interface;

namespace SystemLYH.API.Application.Handlers.QualityHandlers
{
    /// <summary>
    /// 过程质检删除
    /// </summary>
    public class QualityDelectHandlers : IRequestHandler<QualityDelectCommand, int>
    {
        protected readonly IQualityRepository _qualityRepository;
        /// <summary>
        /// 库位构造函数
        /// </summary>
        /// <param name="qualityRepository"></param>
        public QualityDelectHandlers(IQualityRepository qualityRepository)
        {
            _qualityRepository = qualityRepository;
        }
        public async Task<int> Handle(QualityDelectCommand request, CancellationToken cancellationToken)
        {
            var list = (await _qualityRepository.GetAllAsync()).Where(x => request.QualityId.Contains(x.QualityId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                await _qualityRepository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
